perm filename A55.TEX[106,RWF] blob sn#872424 filedate 1989-04-21 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\magnification\magstephalf
C00007 ENDMK
CāŠ—;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a55.tex[106,phy] \today\hfill}

\line{\bf Type Definitions\hfil}

Subrange types are the first of several instances we find in Pascal of
types described explicitly by the programmer. It is possible, and wise,
to give such a type a name, and use the name rather than the description
throughout the program. For example, if we give the type {\tt 0..9} the name
{\tt DIGIT}, variables can be declared using that name:

{\obeylines\obeyspaces\let =\ \tt
        VAR D1,D2: DIGIT;
}

\noindent
functions can have that name as result type:

{\obeylines\obeyspaces\let =\ \tt
        FUNCTION UNITSDIGT(N: INTEGER): DIGIT;
}

\noindent
parameters can be declared to be of that type:

{\obeylines\obeyspaces\let =\ \tt
        PROCEDURE ADDCARRY(IN: DIGIT; CARRY: BOOLEAN; VAR OUT: DIGIT);
}

\noindent
and so on.

Types are given names by type definitions like

{\obeylines\obeyspaces\let =\ \tt
        TYPE DIGIT=0..9; CAPLETTER='A'..'Z';
}

\noindent
in the head of a block. The definitions and declarations in the head
of a block must appear in this order:

\smallskip
\disleft 25pt:(1):
Label declarations (you don't know about these yet)

\disleft 25pt:(2):
Constant definitions

\disleft 25pt:(3):
Type definitions

\disleft 25pt:(4):
Variable declarations

\disleft 25pt:(5):
Procedure/function definitions.

\smallskip
This order makes possible program headings like this one:

{\obeylines\obeyspaces\let =\ \tt
        CONST MINRATE=1; MAXRATE=10;
        TYPE RATING=MINRATE..MAXRATE;
        VAR QUALITY: RATING;
        PROCEDURE GOODENOUGH(X: RATING);
            BEGIN
            IF X<QUALITY THEN
                WRITELN('SUBSTANDARD PERFORMANCE')
            END;
}

\noindent
In the example above, the 1-to-10 range for ratings is mentioned only
in the constant definition, and could be changed to 0-to-20, say, by editing
that single line in the program. Subranges may be defined using symbolic
constants, variables may be declared to be of such subrange types, and
procedures and functions may use the variables.

The general form of a type definition is:

\bigskip
$$\vcenter{\halign{$\hfil#\hfil\qquad$&\hfil{\tt #}\hfil\qquad&\hfil#\hfil\qquad%
&\hfil{\tt #}\hfil\qquad&\hfil#\hfil\qquad&\hfil{\tt #}\hfil\cr
\bullet&TYPE&name&=&type&;\cr
}}$$

\bigskip\noindent
where the types may include the standard types {\tt REAL}, {\tt INTEGER},
{\tt BOOLEAN}, {\tt CHAR}, the subrange types, and the array, record,
pointer and file types described further~on. The type names defined
in the heading of a block may be used throughout the block.



\bigskip
\line{\copyright 1985 Robert W. Floyd; 
First draft (not published) November 1, 1984\hfil}
%revised: Date; subsequently revised.\hfill}

\bye